<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<jsp:include page="../common/adminContentHead.jsp" />
<title>课程设计管理系统</title>

</head>
<body>
	<!-- begin搜索 -->
	<div class="well well-sm" id="searchIntro">
		<form id="searchForm" class="form-inline">
			<div class="row">
				<div class="form-group  col-md-12">
					<div class="input-group">
						<span class="input-group-addon">姓名</span>
						<input class="form-control" name="name">
					</div>
					<div class="input-group" style="width: 250px;">
						<span class="input-group-addon">是否提交报告</span>
						<select class="selectpicker" name="haveSubmit" data-width="100%" data-live-search="true"  id="haveSubmit">
							<option value="">不限</option>
							<option value="1">已提交</option>
							<option value="2">未提交</option>
				 		</select>
					</div>
					<div class="input-group" style="margin-left: 20px;">
						<button type="button" class="btn btn-success" onclick="loadPaging(1)">搜索</button>
						<input type="reset" id="formRest" style="display: none;">
						<button type="button" class="btn btn-success" onclick="resetIntro(1)" style="margin-left: 5px;">重置</button>
					</div>
				</div>
			</div>
		</form>
	</div>
	<div class="row">
		<div class="col-md-12" id="userList">
			<div class="panel panel-default">
				<div class="panel-heading" style="padding: 5px 15px;">
				</div>
				<div class="panel-body hfit" style="overflow-x: auto;">
					<input type="hidden" id="currentUserId">
					<!-- Table -->
				  	<table class="table table-bordered table-hover"  id="table_users_fqj">
					   <thead>
					      <tr>
					      	 <th style="width: 30px;"><input type="checkbox"></th>
					         <th field="orgName">班级</th>
					         <th field="stuName" render="mess">学生姓名</th>
					         <th field="groupName">小组</th>
					         <th field="tasName">课题</th>
					         <th field="cz" render="btndos">操作</th>
					      </tr>
					   </thead>
					</table>
					<div id="table_Paging_fqj"></div>
				</div>
			</div>
		</div>
	</div>
	
	<div id=showMember class="panel panel-default" style="padding: 10px 30px;border: none;display: none;">
		<div class="form-group" id="showMembercontent">
		</div>
		<div class="form-group" >
			<div class="form-group col-md-14">
				<input type="hidden" id="toid">
			  	<textarea  class="form-control" placeholder="内容" id="content" ></textarea>
			</div>
			<div class="form-group col-md-14">
			  	<button type="button" class="btn btn-default form-control repy" >留言</button>
			</div>
		</div>
	</div>
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/system/bootstrapTable.js?v=<%=getServletContext().getAttribute("version") %>"></script>
	<script type="text/javascript">
		/* 初始化 start */
		$(function() {
			var divheight = $(window).height();//初始化修改div的高度
			divheight = divheight - 125;
			$(".hfit").css({
				height : divheight
			});
			loadPaging(1);

		});
		
		function loadUsers(pageNum){
			var url=rootpath+"/group/getmark.shtml";
			var offSet=(pageNum-1)*10;
			var searchData=$("#searchForm").getFormData();
			searchData.offSet=offSet;
			searchData.pageSize=10;
			$.post(url,searchData,function(rows){
				$("#table_users_fqj").table(rows);
				//初始化分页插件
			});
		}
		function loadPaging(pageNum){
			var url=rootpath+"/group/getmark.shtml";
			var offSet=(pageNum-1)*10;
			var searchData=$("#searchForm").getFormData();
			searchData.offSet=offSet;
			searchData.pageSize=10;
			$.post(url,searchData,function(data){
				var rows=data.items;
				var count=data.rowsCount;
				$("#table_users_fqj").table(rows);
				//初始化分页插件
				$("#table_Paging_fqj").tablePaging(1,10,count,"loadUsers");
			});
		}
		/*重置*/
		function resetIntro(){
			$("#searchForm").reset();
			loadPaging(1);
		}
		 
		 
		function mess(e){
			var row=e.row;
			var btns = new Array();
			btns.push('<a href="javascript:void(0);" onclick="showPro('+row.groupId+','+row.stuId+',\''+row.stuName+'\')" >'+row.stuName+'</a>');
			return btns.join("&nbsp;&nbsp;");
		}
		
		/*按钮渲染*/
		function btndos(e){
			var row=e.row;
			if(!row.score){row.score="0";}
			var btns = new Array();
			if(row.finish==0){
				btns.push('<input type="text" style="width: 60px; display: inline-block;" type="number" class="form-control">');
				btns.push('<button type="button" onclick="addScore('+row.gmId+',this)" class="btn btn-default btn-sm addScore">填写成绩</button>');
			}else{
				btns.push(row.score+'分');
			}
			return btns.join("&nbsp;&nbsp;");;
		}
		
		function addScore(id,obj){
			var score=$(obj).prev().val();
		    var url=rootpath+"/group/addScore.shtml";
    	    $.post(url,{"id":id,"score":score},function(data){
    		   if(data){
    			   layer.msg('保存成功');
    			   loadPaging(1);
    			   layer.closeAll();
    		   }else{
    			   layer.msg('保存失败');
    		   }
    	   });
		}
		
		function showPro(groupId,stuId,stuName){
			  $('#toid').val(stuId);
			  $('#showMembercontent').html('');
			  var url=rootpath+"/group/findStuPro.shtml";
	    	    $.post(url,{"gid":groupId,"sid":stuId},function(data){
	    	    	if(data.status){
		    		  	data=jQuery.parseJSON(data.data)
	    	    		var pro='';
	    	    		$.each(data.pro,function(i,obj){
	    	    			if(!obj.comments){obj.comments='';}
	    	    			pro+='<div class="form-inline col-md-12"> <span>完成:'+obj.pro+'%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;描述：<textarea rows="5" cols="30" class="form-control" readonly="readonly" >'+obj.explains+'</textarea>   </span> <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点评：<textarea rows="5" cols="40" class="form-control">'+obj.comments+'</textarea>'+
		    			   '&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-default btn-sm saveComment" id="'+obj.id+'">保存</button> </span> </div>';
	    	    		});
	    	    		pro+='<div class="form-inline col-md-12"> <label>附件</label> </div>';
	    	    		$.each(data.file,function(i,obj){
	    	    			var ur=rootpath+"/"+obj.fUrl
		    	    		pro+='<div class="form-group col-md-14"> <a href="'+ur+'">'+obj.fName+'</a> </div>';
	    	    		});
	    	    		$('#showMembercontent').html(pro);
	    		   }else{
	    			   layer.msg('保存失败');
	    		   }
	    	   });
			 layer.open({
			      type: 1,
			     title: stuName+'的进度',
			      area: ['900px', '500px'],
			   content: $('#showMember') 
			   });
		}
		
		$('#showMember').on('click','.saveComment',function(){
			var comment=$(this).prev().val();
			var id=$(this).attr('id');
			var url=rootpath+"/prog/saveComment.shtml";
	    	$.post(url,{"id":id,"comments":comment},function(data){
	    		   if(data.status){
	    			   layer.msg('保存成功');
	    			   setTimeout(function(){
		    			   layer.closeAll();
	    				},2000);
	    		   }else{
	    			   layer.msg('保存失败');
	    		   }
	    	   });
		});
		
		
		$('.repy').click(function(){
			var toid=$("#toid").val();
			var content=$("#content").val();
			var url = rootpath + "/mess/save.shtml";
			$.post(url,{"content":content,"to":toid},function(data) {
				if(data.status){
					$("#content").val('')
					layer.msg('留言成功');
					layer.closeAll();
				}
			});
		})
		
	</script>
	
</body>
</html>
